<%--
/**
* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.crossriver.crgis.database.model.Individual_Information"%>
<%@ page import="com.crossriver.crgis.database.model.Application_C_of_O" %>
<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>

<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="/init.jsp"%>

<%
Individual_Information individual =(Individual_Information)request.getAttribute(
					ApplicationCofOConstants.IND_INFO_SESSION_ATTR);
	

Application_C_of_O applicatn = 
	Application_C_of_OUtil.findByPrimaryKey(individual.getApplicationId());

%>

<portlet:defineObjects />

<portlet:resourceURL var="ajaxCallResourceURL" />
<portlet:renderURL var="ApplicationCofO2">
<portlet:param name="jspPage" value="/html/individualcofo/ApplicationCofO2.jsp" />
</portlet:renderURL>


<liferay-portlet:actionURL name="savePersonalInformation" var="savePersonalInformation"></liferay-portlet:actionURL>



 <aui:form action="<%=savePersonalInformation.toString() %>" method="post" name="pickApplicationType_fm">

    <% String app = applicatn.getApplication(); %>
 <div id="main">
	<%
	if("certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Certificate Of Occupancy</h1>
	<%
	}else if("re-certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Re-Certificate Of Occupancy</h1>
	<%
	}else {
	%>
	<h1>Application for State Land</h1>
	<%
	}
	%>
	
  <div class="content">
  
  	<liferay-ui:error key="title-is-mandatory" message="title-is-mandatory" />
		<liferay-ui:error key="last-name-is-mandatory" message="last-name-is-mandatory" />
		<liferay-ui:error key="first-name-is-mandatory" message="first-name-is-mandatory" />
		<liferay-ui:error key="occupation-is-mandatory" message="occupation-is-mandatory" />
		<liferay-ui:error key="gender-is-mandatory" message="gender-is-mandatory" />
		<liferay-ui:error key="country-is-mandatory" message="country-is-mandatory" />
		<liferay-ui:error key="identification-is-mandatory" message="identification-is-mandatory" />
		<liferay-ui:error key="identification_number-is-mandatory" message="identification_number-is-mandatory" />
		<liferay-ui:success key="personal-information-save-success" message="personal-information-save-success"></liferay-ui:success>
		
 		<table width="100%" border="0" cellpadding="0" cellspacing="0" >
    <tr>
    	<td width="15%" valign="top">
      	<aui:input name="applicationId" type="hidden" value="<%= individual.getApplicationId() %>"></aui:input>
        <aui:input name="buttonClicked" type="hidden" value=""></aui:input>
        <table width="100%" id="steps" cellpadding="0" cellspacing="0">
       		<tr><td valign="middle" align="center" class="current">STEP 1</td></tr>
       		<tr><td valign="middle" align="center">STEP 2</td></tr>
	        <tr><td valign="middle" align="center">STEP 3</td></tr>
          <tr><td valign="middle" align="center">STEP 4</td></tr>
          <tr><td valign="middle" align="center">STEP 5</td></tr>
          <tr><td valign="middle" align="center">STEP 6</td></tr>
          <tr><td valign="middle" align="center">STEP 7</td></tr>
          <tr><td valign="middle" align="center">STEP 8</td></tr>                               
       	</table>
     	</td>
      <td width="85%" valign="top">
				<table width="100%" id="mainform">
   				<tr><td colspan="3" class="title">Personal Information</td></tr>
       		<tr>
			    	<td colspan="3" align="right" class="buttons">
							<hr>
				 			<aui:button type="button" value="Exit Application"  onClick="exitApplication();"></aui:button>
			            	<aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
			            	<aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
							<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
			      </td>
		      </tr>
					<tr>
						<td colspan="3">
						<%
						List<ListType> greetings = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.title");
						
						%>
						
						<aui:select name="title" label="Title<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
							<option value="">Select Your Title</option>
					  	document.getElementById('title').options.length = 0;
					  	<%
					  	String greeting = individual.getTitle();
					  	for(int i=0; i<greetings.size(); i++){
					  		ListType _greeting = greetings.get(i);
					  	%>	
				  		<aui:option selected="<%= _greeting.getName().equalsIgnoreCase(greeting)  %>" value="<%=_greeting.getName() %>"><%=_greeting.getName()  %></aui:option>
					  	<%
					  	}
					  	%>
						</aui:select>
			  		</td>
					</tr>
          <tr>
          	<td width="33%">
            	<br>
             	<aui:input helpMessage="Enter your Last Name" label="Last Name<span class='mandatoryfld'>*</span>" name="lastName" value="<%= individual.getLastName() %>" first="true" ></aui:input>     
            </td>
            <td width="33%">
              <br>
              <aui:input helpMessage="Enter your First Name" label="First Name<span class='mandatoryfld'>*</span>" name="firstName" value="<%= individual.getFirstName() %>"></aui:input> 
         		</td>
            <td width="33%">
              <br>
              <aui:input helpMessage="Enter your Middle Name" label="Middle Name" name="middleName" value="<%= individual.getMiddleName() %>"></aui:input> 
           	</td>
         	</tr>
      		<tr>
          	<td colspan="2">
	            <br>
	            <label class="aui-field-label" for="<portlet:namespace/>dob">Date Of Birth<span class='mandatoryfld'>*</span></label>
							<%
								Calendar cal = CalendarFactoryUtil.getCalendar(); 
								if (individual.getDateOfBirth() != null){ 
									cal.setTime(individual.getDateOfBirth()); 
									//cal.setTime(individual.getDateOfBirth().getTime())); 
								} 
							
								Calendar current = CalendarFactoryUtil.getCalendar(); 
								%>	 
			                 <liferay-ui:input-date formName="dateOfBirth" 
					      dayParam="dateOfBirthDay"
						      dayValue="<%= cal.get(Calendar.DATE) %>" 
						      disabled="<%= false %>" 
						      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" 
					      monthParam="dateOfBirthMonth"
						      monthValue="<%= cal.get(Calendar.MONTH) %>" 
					      yearParam="dateOfBirthYear"
						      yearValue="<%= cal.get(Calendar.YEAR) - 10 %>" 
						      yearRangeStart="<%= current.get(Calendar.YEAR) - 100 %>" 
						      yearRangeEnd="<%= current.get(Calendar.YEAR) -10  %>" />
 						</td>
            <td>
            	<br>
            	
            	<%
							List<ListType> occupations = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.occupation");
							
							%>
					
							<aui:select name="occupation" label="Occupation<span class='mandatoryfld'>*</span>" listType="dropdownlist" style="width:130px" >
								<option value="">Select Occupation</option>
				  	
						  	<%
						  	String occupation = individual.getOccupation();
						  	for(int i=0; i<occupations.size(); i++){
						  		ListType _occupation = occupations.get(i);
						  	%>	
				  			<aui:option selected="<%= _occupation.getName().equalsIgnoreCase(occupation)  %>" value="<%=_occupation.getName() %>"><%=_occupation.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
           	</td>
         	</tr>
          <tr>
          	<td>
            	<br>
            	
            	<%
							List<ListType> identifications = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.identification");
							%>
					
							<aui:select name="identificationDocument" label="Identification Document<span class='mandatoryfld'>*</span>" listType="dropdownlist" style="width:130px">
								<option value="">Select ID Document</option>
				  	
						  	<%
						  	String identification = individual.getIdentificationDoc();
						  	for(int i=0; i<identifications.size(); i++){
						  		ListType _identification = identifications.get(i);
						  	%>	
						  	<aui:option selected="<%=  _identification.getName().equalsIgnoreCase(identification) %>" value="<%=_identification.getName() %>"><%=_identification.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
           	</td>
            <td>
            	<br>
              <aui:input label="Identification Number<span class='mandatoryfld'>*</span>" name="identificationDocumentNo" value="<%= individual.getIdentificationDocNo() %>"></aui:input> 
            </td>
            <td>
            	&nbsp;
            </td>
          </tr>
      		<tr>
           	<td>
          		<br>
<%--              <aui:column columnWidth="50"> --%>
               		 	<%-- onchange='<%= renderResponse.getNamespace() + "getStates(" + renderResponse.getNamespace()  + "nationality.value);" %>' --%> 
 				 
              <aui:select name="nationality" label="Country<span class='mandatoryfld'>*</span>" helpMessage="" listType="dropdownlist"
 				  		 	
 				  		 	
 				  		 	style="width:130px"> 
 				  			<option label="" value="" > </option>
                  	
	 				  		<%
	 				  		String country = "";
	 				  		if (individual== null  
	 				  				|| individual.getNationality() == null
	 				  				|| individual.getNationality().equalsIgnoreCase("") ){
	 				  			
	 				  		}else{
	 				  			country =  individual.getNationality();
	 				  		}
	 				  		
			                List<Country> countries = CountryServiceUtil.getCountries();
			                
			                for (Country _country : countries) {
			                %> 
			                  		<aui:option selected="<%= _country.getName().equalsIgnoreCase(country) %>" 
			                  		value="<%=_country.getName() %>"><%=_country.getName()  %></aui:option>
				 				<%
				                }
				 				%>
             	</aui:select>				  	
<%--                  </aui:column> --%>
     				</td>
            <td>
            	<br>
            	<aui:input label="State of Origin<span class='mandatoryfld'>*</span>" name="stateOfOrigin" value="<%= individual.getStateOfOrigin() %>"></aui:input>
           		<%-- <%
							List<ListType> states = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.state");
							%>
					
							<aui:select style="width:130px" name="stateOfOrigin" onchange='<%= renderResponse.getNamespace() + "getLGA(" + renderResponse.getNamespace()  + "stateOfOrigin.value);" %>'
						 		label="State of Origin<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
								<option value="">-Select State-</option>
				  	
						  	<%
						  	String stateOfOriginS = individual.getStateOfOrigin();
						  
						  	if (null !=stateOfOriginS && stateOfOriginS !=""){
						  	for(int i=0; i<states.size(); i++){
						  		ListType _states = states.get(i);
						  	%>	
						  	<aui:option selected="<%=  _states.getName().equalsIgnoreCase(stateOfOriginS) %>" 
				                  		value="<%=_states.getName() %>"><%=_states.getName()  %></aui:option>
				                 
						  	<%
						  	}
						  	}
						  	%>
							</aui:select> --%>
           	</td>
            <td>
            	<br>
            	
            	<aui:input label="Local Government<span class='mandatoryfld'>*</span>" name="lga" value="<%= individual.getLga() %>"></aui:input>
            	
           	 	<%-- <%
							List<ListType> lga = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.lga." + individual.getStateOfOrigin() );
							
							%>
					
							<aui:select style="width:130px" name="lga" label="Local Government<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
								<option value="">-Select LGA-</option>
				  	
						  	<%
						  	String LGAS = individual.getLga();
						  	for(int i=0; i<lga.size(); i++){
						  		ListType _lga = lga.get(i);
						  	%>	
				  			<aui:option selected="<%=  _lga.getName().equalsIgnoreCase(LGAS) %>"  value="<%=_lga.getName() %>"><%=_lga.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select> --%>
            	
           	</td>
       		</tr>
          <tr>
          	<td>
            	<br>
            	
             	<%
							List<ListType> children = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.no_of_children");
							
							%>
					
							<aui:select style="width:130px" name="noOfChildren" label="No. Of Children" listType="dropdownlist" >
           	  	<option value="">Select No. of Children</option>
			  	
						  	<%
						  	String child = new Integer(individual.getNoOfChildren()).toString();
						  	for(int i=0; i<children.size(); i++){
						  		ListType _child = children.get(i);
						  	%>	
			  				<aui:option selected="<%=   _child.getName().equalsIgnoreCase(child) %>" value="<%=_child.getName() %>"><%=_child.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
           	</td>
						<td>
             	<br>

             	<%
							List<ListType> educs = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.education");
							
							%>
					
							<aui:select name="education" label="Education" listType="dropdownlist" >
	           		<option value="">Select Attainment</option>
				  	
						  	<%
						  	String educ = individual.getEducation();
						  	for(int i=0; i<educs.size(); i++){
						  		ListType _educ = educs.get(i);
						  	%>	
				  			<aui:option selected="<%= _educ.getName().equalsIgnoreCase(educ) %>" value="<%=_educ.getName() %>"><%=_educ.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
           	</td>                                        
            <td>
            	<br>

             	<%
							List<ListType> genders = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.gender");
							
							%>
							
							<aui:select label="Gender<span class='mandatoryfld'>*</span>" name="gender" listType="dropdownlist" >
	           		<option value="">Select Gender</option>
				  	
						  	<%
						  	String gender = individual.getGender();
						  	for(int i=0; i<genders.size(); i++){
						  		ListType _gender = genders.get(i);
						  	%>	
						  	<aui:option selected="<%= _gender.getName().equalsIgnoreCase(gender) %>" value="<%=_gender.getName() %>"><%=_gender.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
            </td>
          </tr>
          <tr>
          	<td>
            	<br>

             	<%
							List<ListType> maritalStats = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.marital_status");
		             		
							%>
					
							<aui:select name="maritalStatus" label="Marital Status<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
	           		<option value="">Select Marital Status</option>
				  	
						  	<%
						  	String maritalStat = individual.getMaritalStatus();
						  	for(int i=0; i<maritalStats.size(); i++){
						  		ListType _maritalStat = maritalStats.get(i);
						  	%>	
						  	<aui:option selected="<%= _maritalStat.getName().equalsIgnoreCase(maritalStat) %>" value="<%=_maritalStat.getName() %>"><%=_maritalStat.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>

            </td>
           	<td colspan="2">
          		<br>
             	<%
							List<ListType> religions = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.religion");
							
							%>
							
							<aui:select name="religion" label="Religion"  listType="dropdownlist" >
	           		<option value="">Select Religion</option>
				  	
						  	<%
						  	String religion = individual.getReligion();
						  	for(int i=0; i<religions.size(); i++){
						  		ListType _religion = religions.get(i);
						  	%>	
				  			<aui:option selected="<%= _religion.getName().equalsIgnoreCase(religion) %>"  value="<%=_religion.getName() %>"><%=_religion.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
							</aui:select>
          	</td>
          </tr>
          <tr>
      			<td colspan="3">
          	<br>
            	<hr>
              <p><strong>All fields asterisk in "Red" are compulsory</strong></p>
              <p>	It is the applicant’s responsibility to fill out the Personal InformationForm.If a given category does not 
              apply place the letters N/A in the spaceto indicate Not Applicable.</p>
              <p>The Personal Information Form MUST BE filled by the applicant. Your Personal Information Form will be one of 
              the main sources in determining your eligibility for the award of Certificate Of Occupancy.</p>
          	</td>
  				</tr>
          <tr>
				   <td colspan="3" align="right" class="buttons">
					<hr>
		 			<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
	        <aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
	        <aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
					<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
			      </td>
          </tr>
      	</table>
     	</td>
   	</tr>
  	</table>
  </div>
</div>
  		
 <script type="text/javascript">
	function setButtonClicked(id)
	{
	   //alert(id);
	   document.<portlet:namespace/>pickApplicationType_fm.<portlet:namespace/>buttonClicked.value=id;
	  // alert(document.<portlet:namespace/>quick_add_account_fm.<portlet:namespace/>buttonClicked.value);
	    //document.getElementById('jspPage').value=id;
	}


	
	</script>
	 		
</aui:form>

<liferay-portlet:actionURL name="exitApplication" var="exitApplication"></liferay-portlet:actionURL>
<form name="<portlet:namespace/>exitApplication_fm" method="post"	id="<portlet:namespace/>exitApplication_fm" action="<%=exitApplication.toString()%>">
</form>

<script type="text/javascript">
<!--
function exitApplication()
{
	document.forms["<portlet:namespace/>exitApplication_fm"].submit();
}

//-->
</script>

<script type="text/javascript">
<!--


	function confirmPost()
	{
	var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
	if (agree){
		document.forms["<portlet:namespace/>deleteApplication_fm"].submit();
		return true ;
	}
	else{
		return false ;
	}
	}
//-->
</script>
<aui:script>
		
	Liferay.provide(window,
		'<portlet:namespace />getStates',
		function(countryName) {
	var A = AUI();
			var url = '<%= ajaxCallResourceURL.toString() %>';
				A.io.request(
					url,
					{
						//data to be sent to server
						data: {
							<portlet:namespace />countryName: countryName,
							<portlet:namespace />queryType: 'states',
						},
						dataType: 'json',

						on: {
							failure: function() {
							},

							success: function(event, id, obj) {
								var instance = this;


								//JSON Data coming back from Server
								
								var message = instance.get('responseData');
								
								var stateId = message.stateId;
								
								
						document.getElementById('<portlet:namespace />lga').options.length = 0;		
						document.getElementById('<portlet:namespace />stateOfOrigin').options.length = 0;
						var oFieldSelect= document.getElementById('<portlet:namespace />stateOfOrigin');
									var state = document.createElement('option');  
									state.appendChild(document.createTextNode("-select a state-"));
									oFieldSelect.appendChild(state);
							if (stateId>0){
								if (message) {
							 for( i=1; i<=stateId; i++){
								    var param = "param_" + i;
									//alert(param);
									var oFieldSelect= document.getElementById('<portlet:namespace />stateOfOrigin');
									var state = document.createElement('option'); 
									
						
									//state.appendChild(document.createTextNode(message." + param + ")); 
									state.appendChild(document.createTextNode(message[param]));
									oFieldSelect.appendChild(state); 
									  
								  }
								}
								else {
									alert('no data back from server');
								}
								}
							else{
								var oFieldSelect= document.getElementById('<portlet:namespace />stateOfOrigin');
									var state = document.createElement('option');  
									state.appendChild(document.createTextNode("-Not available-"));
									oFieldSelect.appendChild(state); 
								}
							}

						}
					}

				); //END of io Request

		},
		['aui-io']
	);  //End of Provide


Liferay.provide(window,
		'<portlet:namespace />getLGA',
		function(stateName) {
			var A = AUI();
			var url = '<%= ajaxCallResourceURL.toString() %>';
				A.io.request(
					url,
					{
						//data to be sent to server
						data: {
							<portlet:namespace />stateName: stateName,
							<portlet:namespace />queryType: 'LGA',
						},
						dataType: 'json',

						on: {
							failure: function() {
							},

							success: function(event, id, obj) {
								var instance = this;


								//JSON Data coming back from Server
								
								var message = instance.get('responseData');
								
								var stateId = message.stateId;
								
						document.getElementById('<portlet:namespace />lga').options.length = 0;
						var oFieldSelect= document.getElementById('<portlet:namespace />lga');
									var state = document.createElement('option');  
									state.appendChild(document.createTextNode("-select a LGA-"));
									oFieldSelect.appendChild(state);
							if (stateId>0){
								if (message) {
								  for( i=1; i<=stateId; i++){
								    var param = "param_" + i;
									//alert(param);
									var oFieldSelect= document.getElementById('<portlet:namespace />lga');
									var state = document.createElement('option'); 
									
						
									//state.appendChild(document.createTextNode(message." + param + ")); 
									state.appendChild(document.createTextNode(message[param]));
									oFieldSelect.appendChild(state); 
									  
								  }
								}
								else {
									alert('no data back from server');
								}
								}
							else{
								var oFieldSelect= document.getElementById('<portlet:namespace />lga');
									var state = document.createElement('option');  
									state.appendChild(document.createTextNode("-Not available-"));
									oFieldSelect.appendChild(state); 
								}
							}

						}
					}

				); //END of io Request

		},
		['aui-io']
	);  //End of Provide
</aui:script>

<liferay-portlet:actionURL name="deleteApplication" var="deleteApplication"></liferay-portlet:actionURL>
 <aui:form action="<%=deleteApplication.toString() %>" method="post" name="deleteApplication_fm">
  	<aui:input name="applicationId" type="hidden" value="<%= individual.getApplicationId() %>"></aui:input>
 </aui:form>
 
 